//
//  BHFunDetailBottomView.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/6/23.
//

import UIKit
 protocol BHFunDetailBottomViewDelegate: NSObjectProtocol {
    /**0报名  1群聊  2咨询*/
    func funBottomDidSelectTypeAction(type: Int)
}


class BHFunDetailBottomView: UIView {

    var delegate: BHFunDetailBottomViewDelegate?
    
    @IBOutlet weak var applyView: UIView!
    @IBOutlet weak var applyEndTime_label: UILabel!
    
    @IBOutlet weak var askView: UIView!
    @IBOutlet weak var groupChatView: UIView!

    @IBOutlet weak var state_label: UILabel!
    // 未报名 10 已报名17
    @IBOutlet weak var state_top: NSLayoutConstraint!
    
    var model: BHFunDetailInfoModel! {
        didSet {
            self.state_top.constant = model.signStatus == 1 ? 10:17
            self.applyEndTime_label.isHidden = model.signStatus != 1
            
            self.applyEndTime_label.text = model.signupEndTime
            if model.signStatus == 1 {
                self.state_label.text = "立即报名"
            }else if model.signStatus == 2 {
                self.state_label.text = "已报名"
            }else {
                self.state_label.text = "人数已满"
            }
        }
    }

    
    static func loadFromXib() -> BHFunDetailBottomView {
        let viewArray = Bundle.main.loadNibNamed("BHFunDetailBottomView", owner: nil, options: nil)
        let view: BHFunDetailBottomView = viewArray![0] as! BHFunDetailBottomView
        return view
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.applyView.addLayerCorner(25, 0, .white)
        
        self.applyView.addViewAction {[weak self] (_) in
            self?.delegate?.funBottomDidSelectTypeAction(type: 0)
        }
        
        self.groupChatView.addViewAction {[weak self] (_) in
            self?.delegate?.funBottomDidSelectTypeAction(type: 1)
        }
        
        self.askView.addViewAction {[weak self] (_) in
            self?.delegate?.funBottomDidSelectTypeAction(type: 2)
        }
    }
    
    static var bottomHeight: CGFloat {
        get {
            return CGFloat(81)+UIScreen.safeBottomHeight
        }
    }

}
